package br.com.uniban.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "tb_prova_join_questao")
public class ProvaQuestao implements Serializable,Comparable<ProvaQuestao> {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@ManyToOne(cascade = CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name = "id_prova", referencedColumnName = "id_prova",nullable = false)
	private Prova prova;

	@ManyToOne(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinColumn(name = "id_questao", referencedColumnName = "id_questao",nullable = false)
	private QuestoesAvulsas questao;

	private Integer num_questao;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Prova getProva() {
		return prova;
	}

	public void setProva(Prova prova) {
		this.prova = prova;
	}

	public QuestoesAvulsas getQuestao() {
		return questao;
	}

	public void setQuestao(QuestoesAvulsas questao) {
		this.questao = questao;
	}

	public Integer getNum_questao() {
		return num_questao;
	}

	public void setNum_questao(Integer num_questao) {
		this.num_questao = num_questao;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((num_questao == null) ? 0 : num_questao.hashCode());
		result = prime * result + ((prova == null) ? 0 : prova.hashCode());
		result = prime * result + ((questao == null) ? 0 : questao.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProvaQuestao other = (ProvaQuestao) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (num_questao == null) {
			if (other.num_questao != null)
				return false;
		} else if (!num_questao.equals(other.num_questao))
			return false;
		if (prova == null) {
			if (other.prova != null)
				return false;
		} else if (!prova.equals(other.prova))
			return false;
		if (questao == null) {
			if (other.questao != null)
				return false;
		} else if (!questao.equals(other.questao))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ProvaQuestao [id=" + id + ", prova=" + prova + ", questao="
				+ questao + ", num_questao=" + num_questao + "]";
	}

	@Override
	public int compareTo(ProvaQuestao o) {
		return this.num_questao.compareTo(o.num_questao);
	}
}
